package top.moxingwang.javawork.concurrent;

public class ObjWait  extends Thread{
    public static void main(String[] args) {
        Object lock = new Object();
        new ObjWait(lock).start();
        new scratch_25(lock).start();
        try {
//            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        new scratch_25(lock).start();
    }

    private Object lock;

    public ObjWait(Object lock) {
        this.lock = lock;
    }

    public void run() {
        try {
            synchronized (lock) {
                System.out.println(Thread.currentThread().getId() + "------wait start ; time = " + System.currentTimeMillis());
                lock.wait(10000);
                System.out.println(Thread.currentThread().getId() + "------wait ned ; time = " + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}

class scratch_25 extends Thread {
    private Object lock;

    public scratch_25(Object lock) {
        this.lock = lock;
    }

    public void run() {
        synchronized (lock) {
            System.out.println(Thread.currentThread().getId() + "------notify start ; time = " + System.currentTimeMillis());
//            lock.notify();
//            lock.notifyAll();
            System.out.println(Thread.currentThread().getId() + "------notify end ; time = " + System.currentTimeMillis());
        }
    }

}
